/****************************************************************************************************************************
 * @File name:led.c
 * @Author:sunshu
 * @Version:v1.00
 * @Date:2018/01/20
 * @Description:control the color lightning of the led
 * @Others:
 * @Function List:
 * @History:
****************************************************************************************************************************/

#include "stm32f4xx_hal.h"
#include "led.h"
#include "delay.h"
#include "tim.h"

/****************************************************************************************************************************
* @Functions:LedTask()
* @Description:set the led into a different state
* @Input:the state of the led
* @Output:
* @Return:
* @Others:
* @History:
****************************************************************************************************************************/
void LedTask(unsigned char state)
{
    if(state == TEST_START)			//blue
    {
        UserPWM.SetR(0);
        UserPWM.SetG(0);
        UserPWM.SetB(50);
    }
    else if(state == TEST_OK)		// green
    {
        UserPWM.SetR(0);
        UserPWM.SetG(50);
        UserPWM.SetB(0);
    }
    else if(state == TEST_FAIL)	// red
    {
        UserPWM.SetR(50);
        UserPWM.SetG(0);
        UserPWM.SetB(0);
    }
    else if(state == TEST_OFF)
    {
        UserPWM.SetR(0);
        UserPWM.SetG(0);
        UserPWM.SetB(0);
    }
    else if(state == DEV_ERROR)
    {
        UserPWM.SetR(50);
        UserPWM.SetG(50);
        UserPWM.SetB(0);
        delay_ms(200);
        UserPWM.SetR(0);
        UserPWM.SetG(0);
        UserPWM.SetB(0);
        delay_ms(200);
        UserPWM.SetR(50);
        UserPWM.SetG(50);
        UserPWM.SetB(0);
        delay_ms(200);
        UserPWM.SetR(0);
        UserPWM.SetG(0);
        UserPWM.SetB(0);
        delay_ms(200);
    }
}

void LedChargeBat(unsigned char state)
{
    if(state<25)												//red
    {
        UserPWM.SetR(50);
        UserPWM.SetG(0);
        UserPWM.SetB(0);
    }
    else if(state<50 && state >=25)			//white
    {
        UserPWM.SetR(50);
        UserPWM.SetG(50);
        UserPWM.SetB(50);
    }
    else if(state<75 && state >=50)			//yellow
    {
        UserPWM.SetR(50);
        UserPWM.SetG(50);
        UserPWM.SetB(0);
    }
    else																//green
    {
        UserPWM.SetR(0);
        UserPWM.SetG(50);
        UserPWM.SetB(0);
    }
}



